package com.example.springboot01.aware;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * @Description : 注入整个容器
 * Created by cyd on 2021-05-03 09:36:36
 */
@Service
public class AwareService2 implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    /**
     * 利用此重写方法，获得applicationContext对象；
     * 在此类中，就可以使用该对象的所有功能；
     *
     * @param applicationContext context容器
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void useAppContext() {
        String id = applicationContext.getId();
        System.out.println("id:" + id);
    }
}
